<template xmlns:el-col="http://www.w3.org/1999/html">
    <el-form ref="contentForm" :rules="modelFormRules" :model="contentForm" label-width="100px">
        <el-form-item label="运动类型" prop="preActionType" >
            <el-radio-group v-model="contentForm.preActionType" style="width: 60%">
                <el-radio :label="'00'">主动运动</el-radio>
                <el-radio :label="'01'">被动运动</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="是否电刺激" prop="preActionElectricalStatus" >
            <el-radio-group v-model="contentForm.preActionElectricalStatus" style="width: 50%">
                <el-radio  :label="'01'">是</el-radio>
                <el-radio selected :label="'00'">否</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item v-if="contentForm.preActionElectricalStatus =='01'" label="刺激类型" prop="preActionElectrical" >
            <el-radio-group v-if="contentForm.preActionElectrical !==undefined && contentForm.preActionElectrical !==null" v-model="contentForm.preActionElectrical" style="width: 100%">
                <el-radio :label="'02'">方波</el-radio>
                <el-radio :label="'03'">三角波</el-radio>
                <el-radio :label="'04'">梯形波</el-radio>
                <el-radio :label="'05'">锯齿波</el-radio>
            </el-radio-group>
            <el-radio-group v-if="contentForm.preActionElectrical==undefined || contentForm.preActionElectrical==null" v-model="preActionElectrical" style="width: 100%">
                <el-radio :label="'02'">方波</el-radio>
                <el-radio :label="'03'">三角波</el-radio>
                <el-radio :label="'04'">梯形波</el-radio>
                <el-radio :label="'05'">锯齿波</el-radio>
            </el-radio-group>
        </el-form-item>
<!--        <el-form-item   v-if="contentForm.preActionElectricalStatus =='01'" label="幅度值" prop="preActionAmplitude" >-->
<!--            <el-button type="success" plain  @click="downPreAmp">-</el-button>-->
<!--            <el-input v-model="contentForm.preActionAmplitude" readonly style="margin-left: 5px;width: 20%" ref="PreAmp"></el-input>-->
<!--            <el-button type="success" plain style="margin-left: 5px" @click="upPreAmp">+</el-button>-->
<!--        </el-form-item>-->
        <el-form-item   v-if="contentForm.preActionType =='01'" label="左脚运动速度" prop="preActionLeftSpeed" >
            <el-button type="success" plain  @click="downLeftSpeed">-</el-button>
            <el-input type="number" readonly v-model="contentForm.preActionLeftSpeed" :min="1" style="margin-left: 5px;width: 20%" ref="LeftSpeed"></el-input>
            <el-button type="success" plain style="margin-left: 5px" @click="upLeftSpeed">+</el-button>
        </el-form-item>
        <el-form-item   v-if="contentForm.preActionType =='01'" label="右脚运动速度" prop="preActionRightSpeed" >
<!--            <el-button type="success" plain  @click="downRightSpeed">-</el-button>-->
            <el-input type="number" readonly v-model="contentForm.preActionRightSpeed" :min="1" style="margin-left: 40px;width: 20%" ref="RightSpeed"></el-input>
<!--            <el-button type="success" plain style="margin-left: 5px" @click="upRightSpeed">+</el-button>-->
        </el-form-item>
        <el-form-item  label="痉挛值" prop="preActionSpasm" >
            <el-input type="number" v-model="contentForm.preActionSpasm" :min="1"  :max="3" style="width: 20%"  @keyup.native="proving1"></el-input> 级(1,2,3)
        </el-form-item>
        <el-form-item  label="运动时间" prop="preActionTime" >
            <el-input type="number" v-model="contentForm.preActionTime"  :min="1" style="width: 20%"  @keyup.native="proving1"></el-input> 分钟
        </el-form-item>
        <el-button  style="margin-left: 240px" type="primary" v-on:click="save">保 存</el-button>
    </el-form>
</template>

<script>
    export default {
        name: 'patient',
        data() {
            return {
                modelFormRules:{
                    preActionType: [
                        { required: true, message: '请选择运动类型', trigger: 'blur' },
                    ],
                    preActionElectricalStatus: [
                        { required: true, message: '请选择', trigger: 'blur' },
                    ],
                    preActionSpasm: [
                        { required: true, message: '请输入痉挛值', trigger: 'blur' }
                    ],
                    preActionTime: [
                        { required: true, message: '请输入运动时间', trigger: 'blur' }
                    ],
                },
                preActionElectrical:'02'
            }
        },
        props:['name','contentForm'],
        methods: {
            save:function () {
                this.$refs['contentForm'].validate((valid) => {
                    if (valid) {
                        const result={};
                        result.preActionType=this.contentForm.preActionType;
                        result.preActionElectricalStatus =this.contentForm.preActionElectricalStatus;
                        result.preActionTime=this.contentForm.preActionTime;
                        result.name=this.name;
                        //主动 被动
                        if (this.contentForm.preActionType=="01"){
                            if (this.contentForm.preActionLeftSpeed==undefined || this.contentForm.preActionLeftSpeed==null ||this.contentForm.preActionLeftSpeed ==''){
                                this.$message.error("左脚速度未填写");
                                return;
                            }
                            if (this.contentForm.preActionRightSpeed==undefined || this.contentForm.preActionRightSpeed==null ||this.contentForm.preActionRightSpeed ==''){
                                this.$message.error("右脚速度未填写");
                                return;
                            }
                            //左脚
                            result.preActionLeftSpeed=this.contentForm.preActionLeftSpeed;
                            //右脚
                            result.preActionRightSpeed=this.contentForm.preActionRightSpeed;
                        };
                        // //刺激类型
                        // if (this.contentForm.preActionElectricalStatus=="01"){
                        //     if (this.contentForm.preActionElectrical==undefined || this.contentForm.preActionElectrical==null ||this.contentForm.preActionElectrical ==''){
                        //         this.$message.error("电刺激类型未选择");
                        //         return;
                        //     }
                        //     if (this.contentForm.preActionAmplitude==undefined || this.contentForm.preActionAmplitude==null ||this.contentForm.preActionAmplitude ==''){
                        //         this.$message.error("幅度值未填写");
                        //         return;
                        //     }
                        //     //刺激类型
                        //     result.preActionElectrical=this.contentForm.preActionElectrical;
                        //     //幅度值
                        //     result.preActionAmplitude=this.contentForm.preActionAmplitude;
                        // };
                        //是否存在处方记录ID
                        if (this.contentForm.preActionId!==undefined || this.contentForm.preActionId!==null || this.contentForm.preActionId!==''){
                            result.preActionId=this.contentForm.preActionId;
                        }
                        //痉挛值是否在1~3
                        if (this.contentForm.preActionSpasm =="1" || this.contentForm.preActionSpasm=="2" || this.contentForm.preActionSpasm=="3"){
                            result.preActionSpasm=this.contentForm.preActionSpasm;
                        }else{
                            this.$message.error("痉挛值不可用，请重新填写");
                            return;
                        }
                        //运动时间
                        if (this.contentForm.preActionTime<=0){
                            this.$message.error("运动时间不可用，请重新填写");
                            return;
                        }
                        this.$emit('formData', result);
                        this.$message.success("保存成功");
                    }
                });
            },
            proving1(e) {
                var keynum = window.event ? e.keyCode : e.which;   //获取键盘码
                var keychar = String.fromCharCode(keynum);  //获取键盘码对应的字符
                if (keynum ==189|| keynum==190||keynum == 109 || keynum == 110) {
                    this.$message.warning('禁止输入小数以及负数');
                    e.target.value = ' ';
                    return;
                }
                if (keynum==69){
                    this.$message.warning('禁止输入e或E');
                    e.target.value = ' ';
                    return;
                }
            },
            //幅度值 +
            upPreAmp(){
                if (this.contentForm.preActionAmplitude==undefined || this.contentForm.preActionAmplitude ==""){
                    this.$refs.PreAmp.value=1;
                    this.contentForm.preActionAmplitude=1;
                }else{
                    if (this.contentForm.preActionAmplitude<80){
                        this.$refs.PreAmp.value =parseInt(this.contentForm.preActionAmplitude)+1;    // 给有 ref 属性的 input 赋值
                        this.contentForm.preActionAmplitude=parseInt(this.contentForm.preActionAmplitude)+1;
                    }else {//超过80
                        this.$refs.PreAmp.value = 80;    // 给有 ref 属性的 input 赋值
                        this.contentForm.preActionAmplitude=80;
                    }
                }
            },
            //幅度值 -
            downPreAmp(){
                if (this.contentForm.preActionAmplitude<=80 && this.contentForm.preActionAmplitude !==1){
                    this.$refs.PreAmp.value = parseInt(this.contentForm.preActionAmplitude)-1;    // 给有 ref 属性的 input 赋值
                    this.contentForm.preActionAmplitude=parseInt(this.contentForm.preActionAmplitude)-1;
                }
            },
            //左脚运动速度 +
            upLeftSpeed(){
                if (this.contentForm.preActionLeftSpeed==undefined || this.contentForm.preActionLeftSpeed =="" || this.contentForm.preActionRightSpeed==undefined || this.contentForm.preActionRightSpeed ==""){
                    this.$refs.LeftSpeed.value=15;
                    this.contentForm.preActionLeftSpeed=15;
                    this.$refs.RightSpeed.value=15;
                    this.contentForm.preActionRightSpeed=15;
                }else{
                    if (this.contentForm.preActionLeftSpeed<225){
                        this.$refs.LeftSpeed.value = parseInt(this.contentForm.preActionLeftSpeed)+15;    // 给有 ref 属性的 input 赋值
                        this.contentForm.preActionLeftSpeed=parseInt(this.contentForm.preActionLeftSpeed)+15;
                    }else {//超过225
                        this.$refs.LeftSpeed.value = 225;    // 给有 ref 属性的 input 赋值
                        this.contentForm.preActionLeftSpeed=225;
                    }
                    //右脚
                    if (this.contentForm.preActionRightSpeed<225){
                        this.$refs.RightSpeed.value = parseInt(this.contentForm.preActionRightSpeed)+15;    // 给有 ref 属性的 input 赋值
                        this.contentForm.preActionRightSpeed=parseInt(this.contentForm.preActionRightSpeed)+15;
                     }else {//超过225
                        this.$refs.RightSpeed.value = 225;    // 给有 ref 属性的 input 赋值
                        this.contentForm.preActionRightSpeed=225;
                     }
                }
            },
            //左脚运动速度 -
            downLeftSpeed(){
                if (this.contentForm.preActionLeftSpeed>15){
                    this.$refs.LeftSpeed.value = parseInt(this.contentForm.preActionLeftSpeed)-15;    // 给有 ref 属性的 input 赋值
                    this.contentForm.preActionLeftSpeed=parseInt(this.contentForm.preActionLeftSpeed)-15;
                }
                if (this.contentForm.preActionRightSpeed >15){
                    this.$refs.RightSpeed.value = parseInt(this.contentForm.preActionRightSpeed)-15;    // 给有 ref 属性的 input 赋值
                    this.contentForm.preActionRightSpeed=parseInt(this.contentForm.preActionRightSpeed)-15;
                }
            },
            // //右脚运动速度 +
            // upRightSpeed(){
            //     if (this.contentForm.preActionRightSpeed==undefined || this.contentForm.preActionRightSpeed ==""){
            //         this.$refs.RightSpeed.value=15;
            //         this.contentForm.preActionRightSpeed=15;
            //     }else{
            //         if (this.contentForm.preActionRightSpeed<225){
            //             this.$refs.RightSpeed.value = parseInt(this.contentForm.preActionRightSpeed)+15;    // 给有 ref 属性的 input 赋值
            //             this.contentForm.preActionRightSpeed=parseInt(this.contentForm.preActionRightSpeed)+15;
            //         }else {//超过225
            //             this.$refs.RightSpeed.value = 225;    // 给有 ref 属性的 input 赋值
            //             this.contentForm.preActionRightSpeed=225;
            //         }
            //     }
            // },
            // //右脚运动速度 -
            // downRightSpeed(){
            //     if (this.contentForm.preActionRightSpeed<=225 && this.contentForm.preActionRightSpeed !==15){
            //         this.$refs.RightSpeed.value = parseInt(this.contentForm.preActionRightSpeed)-15;    // 给有 ref 属性的 input 赋值
            //         this.contentForm.preActionRightSpeed=parseInt(this.contentForm.preActionRightSpeed)-15;
            //     }
            // },
        },
        watch:{     //监听value的变化，进行相应的操作即可
            name: function(a,b){     //a是value的新值，b是旧值
               this.name=a;
            }
        }
    };
</script>
<style scoped>
</style>
